package org.example.util;

import org.example.RedBlackTree;

public class RedBlackNodeAdapter implements TreePrintUtil.TreeNode {

    private final RedBlackTree.RBNode<?, ?> node;
    public RedBlackNodeAdapter(RedBlackTree.RBNode<?, ?> node) {
        this.node = node;
    }

    @Override
    public String getPrintInfo() {
        return node.getKey() + (node.getColor() == RedBlackTree.BLACK ? "黑" : "红");
    }

    @Override
    public TreePrintUtil.TreeNode getLeftChild() {
        return node.getLeft() == null ? null : new RedBlackNodeAdapter(node.getLeft());
    }

    @Override
    public TreePrintUtil.TreeNode getRightChild() {
        return node.getRight() == null ? null : new RedBlackNodeAdapter(node.getRight());
    }
}
